package concert;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class SelfInvocationAspect {

    @Pointcut("execution(* com.example.beans.SelfInvocation.doSomething(..)) && within(com.example.beans.*)")
    public void doSomething() {}

    @Pointcut("execution(* com.example.beans.SelfInvocation.doOtherThings(..)) && within(com.example.beans.*)")
    public void doOtherThings() {}

    @Around("doSomething()")
    public Object aroundDoSomething(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("before doSomething");
        Object result = joinPoint.proceed();
        System.out.println("after doSomething");
        return result;
    }
    @Around("doOtherThings()")
    public Object aroundDoOtherThing(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("before doOtherThing");
        Object result = joinPoint.proceed();
        System.out.println("after doOtherThing");
        return result;
    }
}
